var prefix = ctx + "module/customerClue"

$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'clueId', 
			title : '线索id' 
		},
				{
			field : 'clueSource', 
			title : '线索来源',
			formatter : function(value, row, index) {
				if (value == '1') {
					return '<span class="label">官网PC</span>';
				} else if (value == '2') {
					return '<span class="label">官网WAP</span>';
				} else if (value == '3') {
					return '<span class="label">CRM-PC</span>';
				} else if (value == '4') {
					return '<span class="label">CRM-WAP</span>';
				}
			}
		},
				{
			field : 'productType', 
			title : '线索产品类型' 
		},
				{
			field : 'createBy', 
			title : '线索负责人' 
		},
		{
			field : 'isHandle', 
			title : '是否处理', 
			formatter : function(value, row, index) {
				if (value == '0') {
					return '<span class="label label-danger">未处理</span>';
				} else if (value == '1') {
					return '<span class="label label-success">已处理</span>';
				}
			}
		},
				{
			field : 'customerName', 
			title : '客户姓名' 
		},
				{
			field : 'customerCellphone', 
			title : '手机号码' 
		},
				{
			field : 'customerAge', 
			title : '年龄' 
		},
				{
			field : 'customerPhone', 
			title : '电话号码' 
		},	
			{
			field : 'clueOperationType', 
			title : '操作类型', 
			formatter : function(value, row, index) {
				if (value == '0') {
					return '<span class="label label-primary">创建线索</span>';
				} else if (value == '1') {
					return '<span class="label label-success">创建订单</span>';
				} else if (value == '2') {
					return '<span class="label label-warning">无需处理</span>';
				} else if (value == '3') {
					return '<span class="label label-danger">丢弃</span>';
				}
			}
		},
			{
			field : 'createTime', 
			title : '创建时间' 
		},
		    {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
            	actions.push('<a class="btn btn-warning btn-sm ' + detailsFlag + '" href="#" title="详情" mce_href="#" onclick="details(\'' + row.clueId + '\')"><i class="fa fa-search"></i></a> ');
				actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.clueId + '\')"><i class="fa fa-edit"></i></a> ');
				actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.clueId + '\')"><i class="fa fa-remove"></i></a>');
				return actions.join('');
            }
        }];
	var url = prefix + "/list";
	$.initTable(columns, url);
});

/* 客户线索-新增 */
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增客户线索", url);
}

/* 客户线索-查询新增 */
function queryAdd() {
    var url = prefix + '/queryAdd';
    layer_showAuto("新增客户线索", url);
}

/* 客户线索-详情*/
function details(clueId) {
    var url = prefix + '/details/' + clueId;
    layer_showAuto("客户线索详情", url);
}

/* 客户线索-修改 */
function edit(clueId) {
    var url = prefix + '/edit/' + clueId;
    layer_showAuto("修改客户线索", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中客户线索吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("clueId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
